import re

from gensim.models import Word2Vec
import pymongo
from matplotlib.font_manager import FontProperties
import jieba

host = '192.168.0.250'
port = 27018
username = 'bashou_dev'
password = 'bashoukejihhrhl123'

mongo_client = pymongo.MongoClient(host, port, connect=False, socketKeepAlive=True, wtimeout=10000, w=1,
                                   waitQueueTimeoutMS=10000)
mongo_client.admin.authenticate(username, password)
db = mongo_client['develop']

stoplist = {}.fromkeys([line.strip() for line in open("./stopwords.txt")])

model = Word2Vec.load('./word2vec.model')
# model = Word2Vec([], sg=1, hs=1, min_count=1, window=3, size=200, workers=4)
# model.save('./word2vec.model')


for key in model.wv.similar_by_word('身份证', topn=10):
    print(key[0], key[1])

# print(model.wv.similarity('广东省', '珠海市'))
# print(model.wv.similarity('珠海市', '西安市'))
# print(model.wv.doesnt_match("广东省 珠海市 西安市".split()))

# from sklearn.manifold import TSNE
#
# from itertools import chain
#
# random_word = list(set(list(chain.from_iterable(sentences))))[0:300]
#
# X_tsne = TSNE(n_components=2, init='pca', random_state=501).fit_transform(model.wv[random_word])
#
# import matplotlib.pyplot as plt
#
# # 解决负号'-'显示为方块的问题
# plt.figure(figsize=(14, 8))
# # myfont = FontProperties(fname='/usr/share/fonts/wqy-zenhei/wqy-zenhei.ttc')
# myfont = FontProperties(fname='/Library/Fonts/Songti.ttc')
#
# plt.scatter(X_tsne[:, 0], X_tsne[:, 1])
# for i in range(len(X_tsne)):
#     x = X_tsne[i][0]
#     y = X_tsne[i][1]
#     plt.text(x, y, random_word[i], fontproperties=myfont, size=10)
#
# plt.show()
# print('finish')

